<?php
require_once("lib/db_connection.php");
$comp_id = $_SESSION['company_id'];
$query_agree = "SELECT * FROM agreement_tbl WHERE company_id='".$comp_id."'";
$result_agree = mysql_query($query_agree) or die("AGREEMENT ".mysql_error());
$count_agree = mysql_num_rows($result_agree);

$ip_1 = $_SERVER["REMOTE_ADDR"];

if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
    else $TheIp=$_SERVER['REMOTE_ADDR'];

$ip_2 = trim($TheIp);

if($count_agree==0)
{
	$query_agree = "INSERT INTO agreement_tbl (company_id,agree,ip_add1,ip_add2)
	VALUES ('".$_SESSION['company_id']."','1','".$ip_1."','".$ip_2."')";
}
if($count_agree!=0)
{
	$query_agree = "UPDATE agreement_tbl SET agree='1',ip_add1='".$ip_1."',ip_add2='".$ip_2."' WHERE company_id='".$_SESSION['company_id']."'";
}
mysql_query($query_agree) or die("AGREE ".mysql_error());
?>